
package wang.Second;

import java.util.ArrayList;

public class Test4 {
    public static void main(String[] args) {
        ArrayList<student> list = new ArrayList<student>();

        student s1 = new student("zhangsan", 22, "wang1");
        student s2 = new student("wangshu", 13, "wang2");
        student s3 = new student("wangyi", 45, "wang3");

        list.add(s1);
        list.add(s2);
        list.add(s3);
        for (int i = 0; i < list.size(); i++) {
            student stu = list.get(i);
            System.out.println(stu.getName() + "," + stu.getAge());
        }
        boolean getid = Getid(list, "wang1");
        System.out.println(getid);

        ArrayList<student> contains = contains(list);
        System.out.println(contains);

        for (int i = 0; i < contains(list).size(); i++) {
            student s = contains(list).get(i);
            System.out.println(s.getName()+ ", "+s.getId()+", "+s.getAge());

        }
    }

    public static boolean Getid(ArrayList<student> list, String id) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getId().equals(id)) {
                return true;
            }
        }
        return false;
    }
    public static  ArrayList<student>  contains( ArrayList<student> list ){
        ArrayList<student>  resultlist=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            student s = list.get(i);
            int age = s.getAge();

            if(age<18){
                resultlist.add(s);
            }
        }
        return resultlist;

    }
}
